/// 动态评论数据模型
/// 包含用户对动态的评论信息
class PostCommentEntity {
  final String commentId;
  final String postId;
  final String authorId; // 评论者ID
  final String content;
  final DateTime commentTime;

  const PostCommentEntity({
    required this.commentId,
    required this.postId,
    required this.authorId,
    required this.content,
    required this.commentTime,
  });

  /// 从JSON创建评论对象
  factory PostCommentEntity.fromJson(Map<String, dynamic> json) {
    return PostCommentEntity(
      commentId: json['commentId'] as String,
      postId: json['postId'] as String,
      authorId: json['authorId'] as String,
      content: json['content'] as String,
      commentTime: DateTime.parse(json['commentTime'] as String),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'commentId': commentId,
      'postId': postId,
      'authorId': authorId,
      'content': content,
      'commentTime': commentTime.toIso8601String(),
    };
  }

  /// 复制评论对象并修改部分属性
  PostCommentEntity copyWith({
    String? commentId,
    String? postId,
    String? authorId,
    String? content,
    DateTime? commentTime,
  }) {
    return PostCommentEntity(
      commentId: commentId ?? this.commentId,
      postId: postId ?? this.postId,
      authorId: authorId ?? this.authorId,
      content: content ?? this.content,
      commentTime: commentTime ?? this.commentTime,
    );
  }

  @override
  String toString() {
    return 'PostCommentEntity(commentId: $commentId, postId: $postId, authorId: $authorId, content: $content)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is PostCommentEntity && other.commentId == commentId;
  }

  @override
  int get hashCode => commentId.hashCode;
}
